package com.zp.study.scloud.consumer.ctrl;

import com.zp.study.scloud.provider.api.ITestService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//@RefreshScope // 打开动态刷新功能
@RestController
@RequestMapping("/test")
public class TestCtrl {

    // 【Dubbo】引用服务提供者接口
    @Reference(version = "1.0.0") // 注意要使用dubbo的注解
    private ITestService testService;

    // 【Nacos配置中心】项目配置 nacos里可修改配置使其直接生效
    @Value("${pro.name}")
    private String username;

    /**
     * 通过Dubbo远程调用provider项目的接口
     * @param string
     * @return
     */
    @GetMapping(value = "/say/{string}")
    public String say(@PathVariable String string) {
        return "Consumer项目[username=" + username + "] 调用Provider接口: " + testService.sayStr(string);
    }

}
